<%-- 
    Document   : class-manage-action
    Created on : Feb 14, 2012, 3:44:12 PM
    Author     : lab
--%>

<%@page import="util.PagingUtil"%>
<%@page import="util.SharingUtil"%>
<%@page import="dto.User"%>
<%@page import="java.util.ArrayList"%>
<%@page import="dao.ClassDAO"%>
<%
    ClassDAO daoClass = new ClassDAO();
    User user = SharingUtil.getUser(session);
    ArrayList<dto.Class> list=new ArrayList<dto.Class>();
    int currentPage = PagingUtil.getPageNumber(request.getParameter("page"));
    if (user.getRole() == User.ADMINISTRATOR) {
        list = daoClass.getClasses(currentPage, PagingUtil.CONST_PAGE_SIZE);
    } else if (user.getRole() == User.TEACHER) {
        list = daoClass.getClassesOfUser(currentPage, PagingUtil.CONST_PAGE_SIZE, user.getId());
    }
    request.setAttribute("list", list);
    if (request.getParameter("selected-id") != null) {
        int id = Integer.parseInt(request.getParameter("selected-id"));
        SharingUtil.setCurrentClass(session, daoClass.getClass(id));
        response.sendRedirect("index.jsp");
    }
%>